package com.smarth.zhizulian.http.observer;

import android.content.Context;

import com.smarth.zhizulian.http.exception.NoNetException;
import com.smarth.zhizulian.http.observer.inter.BaseObserver;
import com.smarth.zhizulian.utils.DialogUtils;
import com.smarth.zhizulian.utils.KumaToast;

import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

/**
 * Created by 18865 on 2017/12/23.
 * 普通页面访问
 */

public abstract class ProgressObserver<T> extends BaseObserver<T> {
    private boolean mIsShowProgress = true;

    /**
     * 显示加载框
     *
     * @param context
     */
    public ProgressObserver(Context context) {
        this(context, true);
    }

    public ProgressObserver(Context context, boolean isShowProgress) {
        super(context);
        this.mIsShowProgress = isShowProgress;
    }

    @Override
    public void onSubscribe(@NonNull Disposable d) {
        super.onSubscribe(d);
        if (mIsShowProgress) {
            DialogUtils.showNetWorkAccess(mOContext);
        }
    }

    @Override
    public void onError(@NonNull Throwable e) {
        super.onError(e);
        if (mIsShowProgress) {
            DialogUtils.closeProgressDialog();
        }
    }

    @Override
    public void onComplete() {
        if (mIsShowProgress) {
            DialogUtils.closeProgressDialog();
        }
    }

//    @Override
//    public void onErrorNoNet(NoNetException e) {
//        super.onErrorNoNet(e);
//        KumaToast.show(mOContext, "暂无网络");
//    }

}
